package com.rentcarRepair.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.pojo.TbMaintainShop;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rentcarRepair.dao.maintainShopMapper;
import com.rentcarRepair.service.maintainShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author caoch
 * @since 2023/2/27 10:24
 **/

@Service("maintainShopServiceImpl")
public class maintainShopServiceImpl extends ServiceImpl<maintainShopMapper, TbMaintainShop> implements maintainShopService {
	@Autowired
	private maintainShopMapper maintainShopMapper;
	/**
	 *添加修理厂
	 * @param shop
	 * @return int
	 */
	public int addShop(TbMaintainShop shop){
		return maintainShopMapper.insert(shop);
	}

	/**
	 * 修改修理厂
	 * @param shop
	 * @return int
	 */
	public int updateShop(TbMaintainShop shop){
		QueryWrapper<TbMaintainShop> wrapper = new QueryWrapper<>();
		wrapper.eq("id", shop.getId());
		return maintainShopMapper.update(shop,wrapper);
	}

	/**
	 * 删除修理厂
	 * @param id
	 * @return int
	 */
	public int removeShop(int id){
		return maintainShopMapper.deleteById(id);
	}

	/**
	 * 模糊查询
	 *
	 * @param shop
	 * @return list
	 */
	public PageInfo<TbMaintainShop> selectShop(Integer currentPage, Integer pageSize, TbMaintainShop shop){
		PageHelper.startPage(currentPage,pageSize);
		QueryWrapper<TbMaintainShop> wrapper = new QueryWrapper<>();
		wrapper.like(shop.getName()!=null,"name",shop.getName()).or().like(shop.getAddress()!=null,"address",shop.getAddress());
		List<TbMaintainShop> tbMaintainShops = maintainShopMapper.selectList(wrapper);
		PageInfo<TbMaintainShop> tbMaintainShopPageInfo = new PageInfo<>(tbMaintainShops);
		return tbMaintainShopPageInfo;
	}
}
